#!/usr/bin/perl
# 
# Exercise 9.8
# 
# Given an arithmetic expression without parentheses, write a subroutine that adds 
# the appropriate parentheses to conform to Perl's precedence rules. (Warning: this is 
# a pretty hard exercise and should be skipped by all but the true believers who have 
# extra time on their hands. See the Perl documentation for the precedence rules.)
#

# Hints to an answer for Exercise 9.8

# I'm not going to give a solution here, but I will give some hints.  Try storing the
# precedence rules in an array, so that you can iterate through the array of rule in the
# order of their precedence; for each precendence rule, see if any of the operators
# are in the expression and add parentheses if they are.
#
# Assume that the experssions are all expressions on positive integers; this will be a
# lot easier than dealing with such objects as exponential numbers, subroutine calls,
# and the like.  Also, you won't have to decide if the minus sign means minus (a binary
# operator) or is a negative sign (a unary operator).  Later, you can add to your code
# to handle these cases.
#
# In fact, I suggest you first try getting something that will parenthesize expressions
# with only, say, + - * / ^, and then expand it to handle more operators.  Start with
# something you can accomplish, then stretch!
#
# You may want to use the Perl functions "index" and "substr", in addition to the regular
# expression matches, to accomplish the insertions of the parentheses.
#
# Good luck!
